// 
// Decompiled by Procyon v0.5.36
// 

package com.orange.boot.dev1.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.util.MultiValueMap;
import org.springframework.http.HttpEntity;
import org.springframework.http.MediaType;
import org.springframework.http.HttpHeaders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.GetMapping;
import com.orange.boot.utils.R;
import com.orange.boot.dev2.service.DiseaseInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/dev1/test"})
@Api(
        tags = {"测试智能诊断，根据图片返回病名"}
)
@CrossOrigin
public class SuanFaController {
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    DiseaseInformationService diseaseInformationService;

    public SuanFaController() {
    }

    @GetMapping({"/nameToID/{name}"})
    public R nameToID(String name) {
        return this.diseaseInformationService.nameToID(name);
    }

    @PostMapping({"/intelligent_diagnosis"})
    public R intelligent_diagnosis(final MultipartFile pic) {
        System.out.println("图片名为：" + pic.getOriginalFilename());
        String url = "http://120.77.156.205:8802/getDiagnose";

        try {
            MultiValueMap<String, Object> bodyParams = new LinkedMultiValueMap();
            ByteArrayResource var10000 = new ByteArrayResource(pic.getBytes()) {
                public String getFilename() {
                    return pic.getOriginalFilename();
                }
            };
            bodyParams.add("pic", pic.getBytes());
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.MULTIPART_FORM_DATA);
            HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity(pic.getBytes(), headers);
            R res = (R)this.restTemplate.postForObject(url, requestEntity, R.class, new Object[0]);
            System.out.println("算法接口返回的数据为：" + res);
            return res;
        } catch (Exception var8) {
            var8.printStackTrace();
            return R.error().message("调用算法失败！");
        }
    }
}
